const app = getApp();

Page({

  data: {

  },

  onLoad: function (options) {

  },

  
  onReady: function () {

  },

  formsubmit: function(e){
    console.log(e);
    wx.request({
      url: 'https://dorm.dormassistant.wang:8080/notice/addNotice',
      method: "POST",
      data: {
        tittle: e.detail.value.title,
        text: e.detail.value.content,
        userId: wx.getStorageSync('openid')
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded;charset=utf8'
      },
      success: function (res) {
        console.log(e);
        if (res.data.success) {
          wx.showToast({
            title: "发布成功",
            icon: '',
            duration: 2000
          });
          wx.navigateBack({
          });
        } else {
          wx.showToast({
            title: "发布失败",
            icon: '',
            duration: 2000
          });
        }
      },
      fail: function (res) {
        wx.showToast({
          title: "网络故障",
          icon: '',
          duration: 2000
        });
      }
    });
  }

})